package com.ostrich.cloud.ostrichGoodsService.app.component;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.MessageDto;

import com.ostrich.cloud.ostrichGoodsService.common.exception.OstrichGoodsException;
import com.ostrich.cloud.ostrichGoodsService.infra.mapper.SecKillMapper;
import com.ostrich.cloud.ostrichGoodsService.infra.model.SecKill;
import com.ostrich.cloud.ostrichGoodsService.infra.model.SecKillOrder;
import com.ostrich.cloud.ostrichGoodsService.service.SecKillService;
import com.ostrich.cloud.ostrichOrderService.client.OrderManagerClient;
import com.ostrich.cloud.ostrichOrderService.client.param.AddKillParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static com.ostrich.cloud.ostrichGoodsService.common.exception.OstrichGoodsExceptionCode.STOCK_DEC_EXCEPTION;


@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumer.group}", topic = "secKill_group")
@Slf4j
public class SecKillListener implements RocketMQListener<MessageDto> {

    @Resource
    private SecKillService secKillService;




    @Override
    public void onMessage(MessageDto messageDto) {
        log.info("接受消息生成订单");
        SecKillOrder secKillOrder = new SecKillOrder();
        secKillOrder.setSecId(messageDto.getSecId());
        secKillOrder.setParentId(messageDto.getParentId());
        secKillService.addSecKillOrder(secKillOrder,messageDto.getLocationId());
        log.info("生成成功");
    }
}
